package ltd.ninefish.framework.systemapi.factory;

import ltd.ninefish.framework.core.result.Result;
import ltd.ninefish.framework.systemapi.dto.SysFileDto;
import ltd.ninefish.framework.systemapi.service.RemoteFileService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author zhaoxiubin
 * create-time 2024-01-16 8:08
 * description 文件服务降级处理
 **/
@Component
public class RemoteFileFallbackFactory implements FallbackFactory<RemoteFileService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteFileFallbackFactory.class);
    @Override
    public RemoteFileService create(Throwable cause) {
        log.error("文件服务调用失败:{}", cause.getMessage());
        return new RemoteFileService()
        {
            @Override
            public Result<SysFileDto> upload(MultipartFile file)
            {
                return Result.fail("上传文件失败:" + cause.getMessage());
            }
        };
    }
}
